<?php
require_once '../../../wp-load.php';
function get_url($news_url) {
	$ch = curl_init ( $news_url );
	curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, TRUE );
	$news = curl_exec ( $ch );
	$count_curl = 0;
	while ( empty ( $news ) && $count_curl <= 5 ) {
		$count_curl ++;
		sleep ( '3' );
		$news = curl_exec ( $ch );
	}
	curl_close ( $ch );
	return $news;
}
//$url_list=get_url('http://slide.eladies.sina.com.cn/');
//$pattern3='|<div class="picBox[\W\w]*?<h2.*?<a.*?href="(.*?)"|';
//preg_match_all($pattern3, $url_list, $matches);
//echo '<pre>';
//print_r($matches['1']);
//echo '</pre>';
if (! isset ( $_GET ['url'] )) {
	exit ( '图片地址不存在' );
}
$news = get_url ( $_GET ['url'] );
$pattern = '|<div id="eData" style="display:none;">([\W\w]*?)</div>|';
preg_match ( $pattern, iconv ( 'gb18030', 'utf-8//IGNORE', $news ), $matches );
if (empty ( $matches )) {
	exit ( '内容匹配错误' );
}
$pattern1 = '|<dt>(.*?)</dt>[\W\w]*?<dd>(.*?)</dd>[\W\w]*?<dd>(.*?)</dd>[\W\w]*?<dd>(.*?)</dd>[\W\w]*?';
$pattern1 .= '<dd>(.*?)</dd>[\W\w]*?<dd>(.*?)</dd>[\W\w]*?<dd>(.*?)</dd>[\W\w]*?<dd>(.*?)</dd>|';
preg_match_all ( $pattern1, $matches ['1'], $matches1, PREG_SET_ORDER );
if (empty ( $matches1 )) {
	exit ( '图片项匹配错误' );
}
$postcontent = empty ( $matches1 ['0'] ['6'] ) ? $matches1 ['0'] ['1'] : $matches1 ['0'] ['6'];
if (strripos ( $postcontent, '<br />' ) == strlen ( $postcontent ) - 6) {
	$postcontent .= '<!--more-->';
} else {
	$postcontent .= '<br /><!--more-->';
}
$postcontent .= '<br /><img src="' . $matches1 ['0'] ['2'] . '" alt="' . $matches1 ['0'] ['1'] . '"><br />' . $matches1 ['0'] ['1'];
$pic_title = $matches1 ['0'] ['1'];
$pic_content = $matches1 ['0'] ['6'];
$post_title = $pic_title;
unset ( $matches1 ['0'] );
foreach ( $matches1 as $m ) {
	$postcontent .= '<br /><img src="' . $m ['2'] . '" alt="' . $m ['1'] . '">';
	if ($m ['1'] != $pic_title) {
		$postcontent .= '<br />' . $m ['1'];
		$pic_title = $m ['1'];
	}
	if ($m ['6'] != $pic_content) {
		$postcontent .= '<br />' . $m ['6'];
		$pic_content = $m ['6'];
	}
}
$postcontent .= '<br /><br />来自<a href="' . $_GET ['url'] . '" target="_blank">' . $_GET ['url'] . '</a>';
$post = array (//'post_status' => 'publish', 
'post_author' => 1, 'post_category' => array (3 ), //'post_date' => '', 
'post_content' => $postcontent, //'post_excerpt' => '', 
'post_title' => $post_title ); //'tags_input' => '', 
//'guid' => '' 
wp_insert_post ( $post );
echo $postcontent;
?>